package com.example.kafka.producer;

import org.apache.kafka.clients.producer.ProducerRecord;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author
 * @description
 * @datetime 2021/6/28 14:24
 */
@RestController
public class ProducerController {
    @Autowired
    private KafkaTemplate<String, Object> kafkaTemplate;
    @GetMapping("send")
    public Object sendMessage(@RequestParam("value") String value) {
        ProducerRecord<String,Object> rec = new ProducerRecord<>("test" ,"key",value);
        kafkaTemplate.send(rec);
        return "OK";
    }

}
